﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using Diablo3.Engine;
using Diablo3.Engine.Property;
using UtilityLibrary.Serialize;

namespace Diablo3.Window
{
    public partial class SelectProperty : Form
    {
        /// <summary>
        /// 装备
        /// </summary>
        public Items Items { get; set; }

        public SelectProperty()
        {
            InitializeComponent();
            Items = new Items();
        }

        public SelectProperty(Items items)
        {
            InitializeComponent();
            Items = items;
            foreach (ItemsProperty p in Items.Properties)
            {
                if (p is Armor)
                {
                    ckBoxArmor.Checked = true;
                    txtArmor.Enabled = true;
                    txtArmor.Text = ((Armor)p).Value.ToString();
                }
                else if (p is ShowDamage)
                {
                    ckBoxShowDamage.Checked = true;
                    txtShowDamage.Enabled = true;
                    txtShowDamage.Text = ((ShowDamage)p).Value.ToString();
                }
                else if (p is Strength)
                {
                    ckBoxStrength.Checked = true;
                    txtStrength.Enabled = true;
                    txtStrength.Text = ((Strength)p).Value.ToString();
                }
                else if (p is Dexterity)
                {
                    ckBoxDexterity.Checked = true;
                    txtDexterity.Enabled = true;
                    txtDexterity.Text = ((Dexterity)p).Value.ToString();
                }
                else if (p is Intelligence)
                {
                    ckBoxIntelligence.Checked = true;
                    txtIntelligence.Enabled = true;
                    txtIntelligence.Text = ((Intelligence)p).Value.ToString();
                }
                else if (p is Vitality)
                {
                    ckBoxVitality.Checked = true;
                    txtVitality.Enabled = true;
                    txtVitality.Text = ((Vitality)p).Value.ToString();
                }
                else if (p is LifePercent)
                {
                    ckBoxLifePercent.Checked = true;
                    txtLifePercent.Enabled = true;
                    txtLifePercent.Text = ((LifePercent)p).Value.ToString();
                }
                else if (p is AllResistance)
                {
                    ckBoxAllResistance.Checked = true;
                    txtAllResistance.Enabled = true;
                    txtAllResistance.Text = ((AllResistance)p).Value.ToString();
                }
                else if (p is PhysicalResistance)
                {
                    ckBoxPhysicalResistance.Checked = true;
                    txtPhysicalResistance.Enabled = true;
                    txtPhysicalResistance.Text = ((PhysicalResistance)p).Value.ToString();
                }
                else if (p is ColdResistance)
                {
                    ckBoxColdResistance.Checked = true;
                    txtColdResistance.Enabled = true;
                    txtColdResistance.Text = ((ColdResistance)p).Value.ToString();
                }
                else if (p is FireResistance)
                {
                    ckBoxFireResistance.Checked = true;
                    txtFireResistance.Enabled = true;
                    txtFireResistance.Text = ((FireResistance)p).Value.ToString();
                }
                else if (p is LightningResistance)
                {
                    ckBoxLightningResistance.Checked = true;
                    txtLightningResistance.Enabled = true;
                    txtLightningResistance.Text = ((LightningResistance)p).Value.ToString();
                }
                else if (p is PoisonResistance)
                {
                    ckBoxPoisonResistance.Checked = true;
                    txtPoisonResistance.Enabled = true;
                    txtPoisonResistance.Text = ((PoisonResistance)p).Value.ToString();
                }
                else if (p is ArcaneHolyResistance)
                {
                    ckBoxArcaneHolyResistance.Checked = true;
                    txtArcaneHolyResistance.Enabled = true;
                    txtArcaneHolyResistance.Text = ((ArcaneHolyResistance)p).Value.ToString();
                }
                else if (p is BlockChance)
                {
                    ckBoxBlockChance.Checked = true;
                    txtBlockChance.Enabled = true;
                    txtBlockChance.Text = ((BlockChance)p).Value.ToString();
                }
                else if (p is BlockValue)
                {
                    ckBoxBlockValue.Checked = true;
                    txtMaxBlockValue.Enabled = true;
                    txtMinBlockValue.Enabled = true;
                    txtMaxBlockValue.Text = ((BlockValue)p).MaxValue.ToString();
                    txtMinBlockValue.Text = ((BlockValue)p).MinValue.ToString();
                }
                else if (p is MeleeDamageReduction)
                {
                    ckBoxMeleeDamageReduction.Checked = true;
                    txtMeleeDamageReduction.Enabled = true;
                    txtMeleeDamageReduction.Text = ((MeleeDamageReduction)p).Value.ToString();
                }
                else if (p is MissileDamageReduction)
                {
                    ckBoxMissileDamageReduction.Checked = true;
                    txtMissileDamageReduction.Enabled = true;
                    txtMissileDamageReduction.Text = ((MissileDamageReduction)p).Value.ToString();
                }
                else if (p is Damage)
                {
                    ckBoxDamage.Checked = true;
                    txtMaxDamage.Enabled = true;
                    txtMinDamage.Enabled = true;
                    txtMaxDamage.Text = ((Damage)p).MaxValue.ToString();
                    txtMinDamage.Text = ((Damage)p).MinValue.ToString();
                }
                else if (p is AttackSpeed)
                {
                    ckBoxAttackSpeed.Checked = true;
                    txtAttackSpeed.Enabled = true;
                    txtAttackSpeed.Text = ((AttackSpeed)p).Value.ToString();
                }
                else if (p is AttackSpeedPercent)
                {
                    ckBoxAttackSpeedPercent.Checked = true;
                    txtAttackSpeedPercent.Enabled = true;
                    txtAttackSpeedPercent.Text = ((AttackSpeedPercent)p).Value.ToString();
                }
                else if (p is CriticalHitChance)
                {
                    ckBoxCriticalHitChance.Checked = true;
                    txtCriticalHitChance.Enabled = true;
                    txtCriticalHitChance.Text = ((CriticalHitChance)p).Value.ToString();
                }
                else if (p is CriticalHitDamage)
                {
                    ckBoxCriticalHitDamage.Checked = true;
                    txtCriticalHitDamage.Enabled = true;
                    txtCriticalHitDamage.Text = ((CriticalHitDamage)p).Value.ToString();
                }
                else if (p is MinDamage)
                {
                    ckBoxMinDamageOnly.Checked = true;
                    txtMinDamageOnly.Enabled = true;
                    txtMinDamageOnly.Text = ((MinDamage)p).Value.ToString();
                }
                else if (p is MaxDamage)
                {
                    ckBoxMaxDamageOnly.Checked = true;
                    txtMaxDamageOnly.Enabled = true;
                    txtMaxDamageOnly.Text = ((MaxDamage)p).Value.ToString();
                }
                else if (p is LifePerHit)
                {
                    ckBoxLifePerHit.Checked = true;
                    txtLifePerHit.Enabled = true;
                    txtLifePerHit.Text = ((LifePerHit)p).Value.ToString();
                }
                else if (p is LifePerKill)
                {
                    ckBoxLifePerKill.Checked = true;
                    txtLifePerKill.Enabled = true;
                    txtLifePerKill.Text = ((LifePerKill)p).Value.ToString();
                }
                else if (p is LifePerSecond)
                {
                    ckBoxLifePerSecond.Checked = true;
                    txtLifePerSecond.Enabled = true;
                    txtLifePerSecond.Text = ((LifePerSecond)p).Value.ToString();
                }
                else if (p is LifeSteal)
                {
                    ckBoxLifeSteal.Checked = true;
                    txtLifeSteal.Enabled = true;
                    txtLifeSteal.Text = ((LifeSteal)p).Value.ToString();
                }
            }

            if (!String.IsNullOrEmpty(items.Image))
            {
                picItems.Image = ImageCompression.ReadImage(Convert.FromBase64String(items.Image));
            }
        }

        private void ckBoxStrength_CheckedChanged(object sender, EventArgs e)
        {
            txtStrength.Enabled = ckBoxStrength.Checked;
            if (ckBoxStrength.Checked)
            {
                txtStrength.Focus();
                txtStrength.SelectAll();
            }
        }

        private void ckBoxDexterity_CheckedChanged(object sender, EventArgs e)
        {
            txtDexterity.Enabled = ckBoxDexterity.Checked;
            if (ckBoxDexterity.Checked)
            {
                txtDexterity.Focus();
                txtDexterity.SelectAll();
            }
        }

        private void ckBoxIntelligence_CheckedChanged(object sender, EventArgs e)
        {
            txtIntelligence.Enabled = ckBoxIntelligence.Checked;
            if (ckBoxIntelligence.Checked)
            {
                txtIntelligence.Focus();
                txtIntelligence.SelectAll();
            }
        }

        private void ckBoxVitality_CheckedChanged(object sender, EventArgs e)
        {
            txtVitality.Enabled = ckBoxVitality.Checked;
            if (ckBoxVitality.Checked)
            {
                txtVitality.Focus();
                txtVitality.SelectAll();
            }
        }

        private void ckBoxLifePercent_CheckedChanged(object sender, EventArgs e)
        {
            txtLifePercent.Enabled = ckBoxLifePercent.Checked;
            if (ckBoxLifePercent.Checked)
            {
                txtLifePercent.Focus();
                txtLifePercent.SelectAll();
            }
        }

        private void ckBoxArmor_CheckedChanged(object sender, EventArgs e)
        {
            txtArmor.Enabled = ckBoxArmor.Checked;
            if (ckBoxArmor.Checked)
            {
                txtArmor.Focus();
                txtArmor.SelectAll();
            }
        }

        private void ckBoxAllResistance_CheckedChanged(object sender, EventArgs e)
        {
            txtAllResistance.Enabled = ckBoxAllResistance.Checked;
            if (ckBoxAllResistance.Checked)
            {
                txtAllResistance.Focus();
                txtAllResistance.SelectAll();
            }
        }

        private void ckBoxPhysicalResistance_CheckedChanged(object sender, EventArgs e)
        {
            txtPhysicalResistance.Enabled = ckBoxPhysicalResistance.Checked;
            if (ckBoxPhysicalResistance.Checked)
            {
                txtPhysicalResistance.Focus();
                txtPhysicalResistance.SelectAll();
            }
        }

        private void ckBoxColdResistance_CheckedChanged(object sender, EventArgs e)
        {
            txtColdResistance.Enabled = ckBoxColdResistance.Checked;
            if (ckBoxColdResistance.Checked)
            {
                txtColdResistance.Focus();
                txtColdResistance.SelectAll();
            }
        }

        private void ckBoxFireResistance_CheckedChanged(object sender, EventArgs e)
        {
            txtFireResistance.Enabled = ckBoxFireResistance.Checked;
            if (ckBoxFireResistance.Checked)
            {
                txtFireResistance.Focus();
                txtFireResistance.SelectAll();
            }
        }

        private void ckBoxLightningResistance_CheckedChanged(object sender, EventArgs e)
        {
            txtLightningResistance.Enabled = ckBoxLightningResistance.Checked;
            if (ckBoxLightningResistance.Checked)
            {
                txtLightningResistance.Focus();
                txtLightningResistance.SelectAll();
            }
        }

        private void ckBoxPoisonResistance_CheckedChanged(object sender, EventArgs e)
        {
            txtPoisonResistance.Enabled = ckBoxPoisonResistance.Checked;
            if (ckBoxPoisonResistance.Checked)
            {
                txtPoisonResistance.Focus();
                txtPoisonResistance.SelectAll();
            }
        }

        private void ckBoxArcaneHolyResistance_CheckedChanged(object sender, EventArgs e)
        {
            txtArcaneHolyResistance.Enabled = ckBoxArcaneHolyResistance.Checked;
            if (ckBoxArcaneHolyResistance.Checked)
            {
                txtArcaneHolyResistance.Focus();
                txtArcaneHolyResistance.SelectAll();
            }
        }

        private void ckBoxBlockChance_CheckedChanged(object sender, EventArgs e)
        {
            txtBlockChance.Enabled = ckBoxBlockChance.Checked;
            if (ckBoxBlockChance.Checked)
            {
                txtBlockChance.Focus();
                txtBlockChance.SelectAll();
            }
        }

        private void ckBoxBlockValue_CheckedChanged(object sender, EventArgs e)
        {
            txtMaxBlockValue.Enabled = ckBoxBlockValue.Checked;
            txtMinBlockValue.Enabled = ckBoxBlockValue.Checked;
            if (ckBoxBlockValue.Checked)
            {
                txtMinBlockValue.Focus();
                txtMinBlockValue.SelectAll();
            }
        }

        private void ckBoxMissileDamageReduction_CheckedChanged(object sender, EventArgs e)
        {
            txtMissileDamageReduction.Enabled = ckBoxMissileDamageReduction.Checked;
            if (ckBoxMissileDamageReduction.Checked)
            {
                txtMissileDamageReduction.Focus();
                txtMissileDamageReduction.SelectAll();
            }
        }

        private void ckBoxAttackSpeed_CheckedChanged(object sender, EventArgs e)
        {
            txtAttackSpeed.Enabled = ckBoxAttackSpeed.Checked;
            if (ckBoxAttackSpeed.Checked)
            {
                txtAttackSpeed.Focus();
                txtAttackSpeed.SelectAll();
            }
        }

        private void ckBoxAttackSpeedPercent_CheckedChanged(object sender, EventArgs e)
        {
            txtAttackSpeedPercent.Enabled = ckBoxAttackSpeedPercent.Checked;
            if (ckBoxAttackSpeedPercent.Checked)
            {
                txtAttackSpeedPercent.Focus();
                txtAttackSpeedPercent.SelectAll();
            }
        }

        private void ckBoxCriticalHitChance_CheckedChanged(object sender, EventArgs e)
        {
            txtCriticalHitChance.Enabled = ckBoxCriticalHitChance.Checked;
            if (ckBoxCriticalHitChance.Checked)
            {
                txtCriticalHitChance.Focus();
                txtCriticalHitChance.SelectAll();
            }
        }

        private void ckBoxCriticalHitDamage_CheckedChanged(object sender, EventArgs e)
        {
            txtCriticalHitDamage.Enabled = ckBoxCriticalHitDamage.Checked;
            if (ckBoxCriticalHitDamage.Checked)
            {
                txtCriticalHitDamage.Focus();
                txtCriticalHitDamage.SelectAll();
            }
        }

        private void ckBoxMeleeDamageReduction_CheckedChanged(object sender, EventArgs e)
        {
            txtMeleeDamageReduction.Enabled = ckBoxMeleeDamageReduction.Checked;
            if (ckBoxMeleeDamageReduction.Checked)
            {
                txtMeleeDamageReduction.Focus();
                txtMeleeDamageReduction.SelectAll();
            }
        }

        private void ckBoxMinDamageOnly_CheckedChanged(object sender, EventArgs e)
        {
            txtMinDamageOnly.Enabled = ckBoxMinDamageOnly.Checked;
            if (ckBoxMinDamageOnly.Checked)
            {
                txtMinDamageOnly.Focus();
                txtMinDamageOnly.SelectAll();
            }
        }

        private void ckBoxMaxDamageOnly_CheckedChanged(object sender, EventArgs e)
        {
            txtMaxDamageOnly.Enabled = ckBoxMaxDamageOnly.Checked;
            if (ckBoxMaxDamageOnly.Checked)
            {
                txtMaxDamageOnly.Focus();
                txtMaxDamageOnly.SelectAll();
            }
        }

        private void ckBoxDamage_CheckedChanged(object sender, EventArgs e)
        {
            txtMaxDamage.Enabled = ckBoxDamage.Checked;
            txtMinDamage.Enabled = ckBoxDamage.Checked;
            if (ckBoxDamage.Checked)
            {
                txtMinDamage.Focus();
                txtMinDamage.SelectAll();
            }
        }

        private void ckBoxLifePerHit_CheckedChanged(object sender, EventArgs e)
        {
            txtLifePerHit.Enabled = ckBoxLifePerHit.Checked;
            if (ckBoxLifePerHit.Checked)
            {
                txtLifePerHit.Focus();
                txtLifePerHit.SelectAll();
            }
        }

        private void ckBoxLifePerKill_CheckedChanged(object sender, EventArgs e)
        {
            txtLifePerKill.Enabled = ckBoxLifePerKill.Checked;
            if (ckBoxLifePerKill.Checked)
            {
                txtLifePerKill.Focus();
                txtLifePerKill.SelectAll();
            }
        }

        private void ckBoxLifeSteal_CheckedChanged(object sender, EventArgs e)
        {
            txtLifeSteal.Enabled = ckBoxLifeSteal.Checked;
            if (ckBoxLifeSteal.Checked)
            {
                txtLifeSteal.Focus();
                txtLifeSteal.SelectAll();
            }
        }

        private void ckBoxLifePerSecond_CheckedChanged(object sender, EventArgs e)
        {
            txtLifePerSecond.Enabled = ckBoxLifePerSecond.Checked;
            if (ckBoxLifePerSecond.Checked)
            {
                txtLifePerSecond.Focus();
                txtLifePerSecond.SelectAll();
            }
        }

        private void ckBoxShowDamage_CheckedChanged(object sender, EventArgs e)
        {
            txtShowDamage.Enabled = ckBoxShowDamage.Checked;
            if (ckBoxShowDamage.Checked)
            {
                txtShowDamage.Focus();
                txtShowDamage.SelectAll();
            }
        }

        private void KeyPressValidate(object sender, KeyPressEventArgs e)
        {
            e.Handled = true;
            if ((e.KeyChar >= '0' && e.KeyChar <= '9') || e.KeyChar == '.' || e.KeyChar == (char)8)
            {
                e.Handled = false;
            }
        }

        private void EmptyLeave(object sender, EventArgs e)
        {
            TextBox txt = sender as TextBox;
            if (txt != null)
            {
                if (String.IsNullOrEmpty(txt.Text))
                {
                    txt.Enabled = false;
                    CheckBox ckBox = this.Controls.Find(String.Format("ckBox{0}", txt.Name.Replace("txt", "")), true)[0] as CheckBox;
                    if (ckBox != null)
                    {
                        if (this.ActiveControl != ckBox) ckBox.Checked = false;
                    }
                }
            }
        }

        private void btnSubmit_Click(object sender, EventArgs e)
        {
            Items.Properties.Clear();
            if (ckBoxArmor.Checked)
            {
                Items.Properties.Add(new Armor(Convert.ToDouble(txtArmor.Text)));
            }
            if (ckBoxShowDamage.Checked)
            {
                Items.Properties.Add(new ShowDamage(Convert.ToDouble(txtShowDamage.Text)));
            }
            if (ckBoxDamage.Checked)
            {
                Items.Properties.Add(new Damage(Convert.ToDouble(txtMinDamage.Text), Convert.ToDouble(txtMaxDamage.Text)));
            }
            if (ckBoxMinDamageOnly.Checked)
            {
                Items.Properties.Add(new MinDamage(Convert.ToDouble(txtMinDamageOnly.Text)));
            }
            if (ckBoxMaxDamageOnly.Checked)
            {
                Items.Properties.Add(new MaxDamage(Convert.ToDouble(txtMaxDamageOnly.Text)));
            }
            if (ckBoxAttackSpeed.Checked)
            {
                Items.Properties.Add(new AttackSpeed(Convert.ToDouble(txtAttackSpeed.Text)));
            }
            if (ckBoxAttackSpeedPercent.Checked)
            {
                Items.Properties.Add(new AttackSpeedPercent(Convert.ToDouble(txtAttackSpeedPercent.Text)));
            }
            if (ckBoxCriticalHitChance.Checked)
            {
                Items.Properties.Add(new CriticalHitChance(Convert.ToDouble(txtCriticalHitChance.Text)));
            }
            if (ckBoxCriticalHitDamage.Checked)
            {
                Items.Properties.Add(new CriticalHitDamage(Convert.ToDouble(txtCriticalHitDamage.Text)));
            }
            if (ckBoxBlockChance.Checked)
            {
                Items.Properties.Add(new BlockChance(Convert.ToDouble(txtBlockChance.Text)));
            }
            if (ckBoxBlockValue.Checked)
            {
                Items.Properties.Add(new BlockValue(Convert.ToDouble(txtMinBlockValue.Text), Convert.ToDouble(txtMaxBlockValue.Text)));
            }
            if (ckBoxStrength.Checked)
            {
                Items.Properties.Add(new Strength(Convert.ToDouble(txtStrength.Text)));
            }
            if (ckBoxDexterity.Checked)
            {
                Items.Properties.Add(new Dexterity(Convert.ToDouble(txtDexterity.Text)));
            }
            if (ckBoxIntelligence.Checked)
            {
                Items.Properties.Add(new Intelligence(Convert.ToDouble(txtIntelligence.Text)));
            }
            if (ckBoxVitality.Checked)
            {
                Items.Properties.Add(new Vitality(Convert.ToDouble(txtVitality.Text)));
            }
            if (ckBoxLifePercent.Checked)
            {
                Items.Properties.Add(new LifePercent(Convert.ToDouble(txtLifePercent.Text)));
            }
            if (ckBoxAllResistance.Checked)
            {
                Items.Properties.Add(new AllResistance(Convert.ToDouble(txtAllResistance.Text)));
            }
            if (ckBoxPhysicalResistance.Checked)
            {
                Items.Properties.Add(new PhysicalResistance(Convert.ToDouble(txtPhysicalResistance.Text)));
            }
            if (ckBoxColdResistance.Checked)
            {
                Items.Properties.Add(new ColdResistance(Convert.ToDouble(txtColdResistance.Text)));
            }
            if (ckBoxFireResistance.Checked)
            {
                Items.Properties.Add(new FireResistance(Convert.ToDouble(txtFireResistance.Text)));
            }
            if (ckBoxLightningResistance.Checked)
            {
                Items.Properties.Add(new LightningResistance(Convert.ToDouble(txtLightningResistance.Text)));
            }
            if (ckBoxPoisonResistance.Checked)
            {
                Items.Properties.Add(new PoisonResistance(Convert.ToDouble(txtPoisonResistance.Text)));
            }
            if (ckBoxArcaneHolyResistance.Checked)
            {
                Items.Properties.Add(new ArcaneHolyResistance(Convert.ToDouble(txtArcaneHolyResistance.Text)));
            }
            if (ckBoxMeleeDamageReduction.Checked)
            {
                Items.Properties.Add(new MeleeDamageReduction(Convert.ToDouble(txtMeleeDamageReduction.Text)));
            }
            if (ckBoxMissileDamageReduction.Checked)
            {
                Items.Properties.Add(new MissileDamageReduction(Convert.ToDouble(txtMissileDamageReduction.Text)));
            }
            if (ckBoxLifePerHit.Checked)
            {
                Items.Properties.Add(new LifePerHit(Convert.ToDouble(txtLifePerHit.Text)));
            }
            if (ckBoxLifePerKill.Checked)
            {
                Items.Properties.Add(new LifePerKill(Convert.ToDouble(txtLifePerKill.Text)));
            }
            if (ckBoxLifePerSecond.Checked)
            {
                Items.Properties.Add(new LifePerSecond(Convert.ToDouble(txtLifePerSecond.Text)));
            }
            if (ckBoxLifeSteal.Checked)
            {
                Items.Properties.Add(new LifeSteal(Convert.ToDouble(txtLifeSteal.Text)));
            }

            if (picItems.Image != null)
            {
                Items.Image = Convert.ToBase64String(ImageCompression.ConvertImage(picItems.Image));
            }
            else
            {
                Items.Image = null;
            }

            this.DialogResult = System.Windows.Forms.DialogResult.OK;
        }

        private void txtBlockValue_Leave(object sender, EventArgs e)
        {
            if (String.IsNullOrEmpty(txtMaxBlockValue.Text) || String.IsNullOrEmpty(txtMinBlockValue.Text))
            {
                if (this.ActiveControl != txtMaxBlockValue && this.ActiveControl != txtMinBlockValue)
                {
                    txtMaxBlockValue.Enabled = false;
                    txtMinBlockValue.Enabled = false;

                    if (this.ActiveControl != ckBoxBlockValue) ckBoxBlockValue.Checked = false;
                }
            }
        }

        private void txtDamage_Leave(object sender, EventArgs e)
        {
            if (String.IsNullOrEmpty(txtMaxDamage.Text) || String.IsNullOrEmpty(txtMinDamage.Text))
            {
                if (this.ActiveControl != txtMaxDamage && this.ActiveControl != txtMinDamage)
                {
                    txtMaxDamage.Enabled = false;
                    txtMinDamage.Enabled = false;

                    if (this.ActiveControl != ckBoxDamage) ckBoxDamage.Checked = false;
                }
            }
        }

        private void picItems_Click(object sender, EventArgs e)
        {
            if (picItems.Image == null)
            {
                IDataObject data = System.Windows.Forms.Clipboard.GetDataObject();
                if (data.GetDataPresent(typeof(Bitmap)))
                {
                    Image photo = (Image)data.GetData(typeof(Bitmap));
                    picItems.Image = photo;
                }
            }
        }

        private void button1_Click(object sender, EventArgs e)
        {
            picItems.Image = null;
        }
    }
}
